package jdbc;

import com.mysql.cj.xdevapi.DbDoc;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;

public class JdbcDemo12
{
    public static void main(String[] args)
    {
        try(Connection c = DBUtil.getConnection())
        {
            c.setAutoCommit(false);  // 关闭自动提交
            String sql = "delete from userinfo1 where id = 2";
            Statement statement = c.createStatement();
            int num = statement.executeUpdate(sql);
            if (num > 0 )
            {
                System.out.println("删除成功");
            }else
            {
                System.out.println("删除失败");
            }

            // 无论执行commit  或者是 rollback  都睡导致事物结束
//            c.rollback();
            c.commit();


        }catch (SQLException e)
        {
            e.printStackTrace();
        }
    }
}
